package dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import bd.CriarTabela;
import bean.Tarefa;

public class TarefaDao {

	public static void adicionarTarefa(Tarefa tarefa){

		Session session = CriarTabela.preparaSessao();
		session.save(tarefa);
		session.beginTransaction().commit();
		session.close();	
	}
	
	public static List<Tarefa> retornarTodasAsTarefas() {
		Session session = CriarTabela.preparaSessao();
		return session.createCriteria(Tarefa.class).list();
	}
	
	public static void deletarTarefa(Tarefa tarefa)
	{
		Session session = CriarTabela.preparaSessao();
		Transaction transaction = session.beginTransaction();
		Tarefa tarefaBd = (Tarefa)session.load(Tarefa.class, tarefa.getId());
		session.delete(tarefaBd);
		transaction.commit();
		session.close();
		
	}
}